﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TeamNitro.Student
{
    public partial class Students_Change_Elective : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DBManager_Jowie db = (DBManager_Jowie)Session["Student"];
            DBManager_Jowie dbJowie1 = dbJowie1 = DBManager_Jowie.CurrentElectiveSubject(db.AdminNumber);

            if (dbJowie1 == null)
            {
                lblSub.Text = "0";
                Label4.Visible = true;
            }
            else
            {
                lblSub.Text = dbJowie1.ElectiveName;
                Label2.Visible = true;
                Label3.Visible = true;
                ddElective.Visible = true;
                tbxComment.Visible = true;
                Button3.Visible = true;
                btnSubmitComment.Visible = true;

                List<DBManager_Jowie> dbJowie2 = DBManager_Jowie.GetElectiveSubjects(db.CourseCode);
                for (int i = 0; i < dbJowie2.Count(); i++)
                {
                    if (dbJowie2[i].ElectiveName != dbJowie1.ElectiveName)
                    {
                        ddElective.Items.Add(dbJowie2[i].ElectiveName);
                    }
                }
            }
            
        }

        protected void btnSubmitComment_Click(object sender, EventArgs e)
        {
            DBManager_Jowie db = (DBManager_Jowie)Session["Student"];
            DBManager_Jowie dbJowie1 = new DBManager_Jowie();
            dbJowie1 = DBManager_Jowie.CurrentElectiveSubject(db.AdminNumber);
            List<DBManager_Jowie> dbJowie2 = DBManager_Jowie.GetElectiveSubjects(db.CourseCode);

            DBManager_Jowie dbJowie = new DBManager_Jowie();
            dbJowie.AdminNumber = db.AdminNumber;

            dbJowie.ElectiveCode = dbJowie1.ElectiveCode;
            dbJowie.ElectiveName = dbJowie1.ElectiveName;

            for (int i = 0; i < dbJowie2.Count(); i++)
            {
                if (ddElective.SelectedValue == dbJowie2[i].ElectiveName)
                {
                    dbJowie.ChangeElectiveCode = dbJowie2[i].ElectiveCode;
                    dbJowie.ChangeElectiveName = dbJowie2[i].ElectiveName;
                    break;
                }
            }

            dbJowie.Comment = tbxComment.Text;
            DBManager_Jowie.ChangeElectiveSubject(dbJowie);

            ddElective.Items.Clear();
            for (int i = 0; i < dbJowie2.Count(); i++)
            {
                if (dbJowie2[i].ElectiveName != dbJowie1.ElectiveName)
                {
                    ddElective.Items.Add(dbJowie2[i].ElectiveName);
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

        }

        
    }
}